﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MessageViewControl 
{    
    Queue<MessageViewBase> _queueMessageView = new Queue<MessageViewBase>();

    MemoryPool<MessageToView> _messageToViewPool = new MemoryPool<MessageToView>(100);
    MemoryPool<ViewToMessage> _viewToMessagePool = new MemoryPool<ViewToMessage>(100);
    

    private void Enqueue(MessageViewBase messageView)
    {
        _queueMessageView.Enqueue(messageView);
    }

    public void UpdatePop()
    {
        if (_queueMessageView.Count > 0)
        {
            MessageViewBase messageView = _queueMessageView.Dequeue();
            messageView.Handle();

            if (messageView._classType == 1)
                _messageToViewPool.Push((MessageToView)messageView);
            else
                _viewToMessagePool.Push((ViewToMessage)messageView);
        }
    }

    public void SingleMoveCharacter(Character gameChar, MoveDirection dir, float fDT)
    {
        MessageToView messageToView = _messageToViewPool.Pop();
        messageToView.SetFactor(gameChar, dir, fDT, MessageViewType.MTV_single_move);
        Enqueue(messageToView);
    }

    public void SingleRotateGunBarrel(Character gameChar, int upDown, float fDT)
    {
        MessageToView messageToView = _messageToViewPool.Pop();
        messageToView.SetFactor(gameChar, upDown, fDT, MessageViewType.MTV_single_gunbarrelRotate);
        Enqueue(messageToView);
    }

    public void SingleFireGun(Character gameChar)
    {
        MessageToView messageToView = _messageToViewPool.Pop();
        messageToView.SetFactor(gameChar, MessageViewType.MTV_single_fire);
        Enqueue(messageToView);
    }

    public void SingleExplosion(Vector2 collPixel)
    {
        ViewToMessage viewToMessage = _viewToMessagePool.Pop();
        viewToMessage.SetFactor(collPixel, MessageViewType.VTM_single_explosion);
        Enqueue(viewToMessage);
    }
}